<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="" autocomplete="off">


    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Userid')}:</label>
        <div class="col-xs-12 col-sm-8">
		    <input id="c-userid" data-rule="required" data-source="/api/base/user" data-primary-key="userid" data-field="username"  data-params='{"custom[id]":"1"}' disabled class="form-control selectpage" name="row[userid]" type="text" value="{$row.userid}">
     
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('User.Round_proportion')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-round_proportion" data-rule="required" class="form-control" step="0.1" name="row[round_proportion]" type="number" value="{$row.round_proportion}">
			<span class="help-block">{:__('User.Round_note')}</span>
        </div>
    </div>
<!--     <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('User.Integral_proportion')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-integral_proportion" data-rule="required" class="form-control" step="0.1" name="row[integral_proportion]" type="number" 
			value="{$row.integral_proportion}">
			<span class="help-block">{:__('User.Integral_note')}</span>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('User.Books_proportion')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-books_proportion" data-rule="required" class="form-control" step="0.1" name="row[books_proportion]" type="number" 
			value="{$row.books_proportion}">
			<span class="help-block">{:__('User.Books_note')}</span>
        </div>
    </div> -->
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('User.Status')}:</label>
        <div class="col-xs-12 col-sm-8">
            
            <div class="radio">
            {foreach name="$WeekInfo['statusList']" item="vo"}
            <label for="row[status]-{$key}"><input id="row[status]-{$key}"  name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label> 
            {/foreach}
            </div>

        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Desc')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-desc" class="form-control" rows="5" name="row[desc]" cols="50">{$row.desc}</textarea>
        </div>
    </div>
   
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
          
        </div>
    </div>
</form>

<script type="text/javascript">
window.onload=function(){
      //do something
	 document.querySelector('#c-userid').change = function() {
		var value = document.querySelector("#c-userid").value;
	    Fast.api.ajax({
                url: '/api/base/position_new',
				data: {"userid":value},
            }, function (result) { //success
				//console.log(result);
				if(result.length > 0){
					default_value('',1);
					for(var i=0; i<	result.length; i++){ 
						//console.log('11');
						default_value(result[i],i);
					}
				}else{
					default_value('',1);
				}
                return false;
            }, function () { //success
				default_value('',1);
                return false;
            });
	};
}
function default_value(value,ii){
	var select = document.querySelector('.selectpicker');  
	if(value){
		//console.log('1');
		for(var i=0; i<select.options.length; i++){  
			if(select.options[i].value == value){  
				select.options[i].selected = true;  
				if(ii == 0){
					document.querySelector('.dropdown-toggle').title =  select.options[i].innerHTML;
					document.querySelector('.filter-option').innerHTML =  select.options[i].innerHTML;
					document.querySelector('.dropdown-toggle').classList.remove("bs-placeholder");
				}else{
					document.querySelector('.dropdown-toggle').title +=','+select.options[i].innerHTML;
					document.querySelector('.filter-option').innerHTML +=','+select.options[i].innerHTML;
				}
				default_valueSelect(1,i);
			}
		} 
	}else{
		//console.log('-1');
		for(var i=0; i<select.options.length; i++){  
			select.options[i].selected = false;
		} 
		//console.log(select.options);
		//document.all.objSelect.options.selected = false;
		document.querySelector('.dropdown-toggle').classList.remove("bs-placeholder");
		document.querySelector('.dropdown-toggle').title ='没有选中任何项';
		document.querySelector('.filter-option').innerHTML ='没有选中任何项';
		document.querySelector('.dropdown-toggle').className += ' bs-placeholder';
		default_valueSelect('-1');
		
	}
}
function default_valueSelect(type,iii){
    var List = document.querySelector('.dropdown-menu');
	var lilist = List.getElementsByTagName('li');
	if(type == 1){
		lilist[iii].className = 'selected';
	}else{
		//console.log('-2');
		for (var i=0;i<lilist.length ;i++ ){
			//console.log(lilist[i]);
			//console.log(lilist[i].hasAttribute('class'));
			if(lilist[i].hasAttribute('class') != false){
				lilist[i].classList.remove("selected");
			}
		}
	}
	//console.log('11111');
           
}

</script>